/*
 * This is GPL v2 licensed code. See the file LICENSE in the
 * source distribution, or www.gnu.org/copyleft/gpl.html, for
 * more information.
 *
 * Copyright (C) by Håkan Lindqvist 2006, 2007
 */

package PolicyTool;

import PolicyAlgebra.Controller.Controller;
import PolicyAlgebra.Plugin.Plugin;
import PolicyAlgebra.Plugin.PluginLoader;
import PolicyAlgebra.Tool.Tool;
import PolicyAlgebra.Util.JarClassLoader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/** 
 * This is the console tool for interacting with the policy algebra
 * packages.
 */
public class PolicyTool implements Tool {

	public static void main(String[] args) throws Exception {
		Plugin p = PluginLoader.getInstance().loadPlugin("text");
		p.importPolicy(args[0]);
	}



	/** 
	 * Ask for a password. 
	 * 
	 * @param prompt The input request description.
	 * @return The password.
	 */
	public String getPassword(String prompt) {
		String ret;

		try {
			ret = new PasswordReader().getPassword(prompt);
		} catch(IOException e) {
			return null;
		}

		return ret;
	}


	/** 
	 * Ask for some input, this differ from the password
	 * method in that the password input should hide the
	 * input while this doesn't have to.
	 * 
	 * @param prompt The input request description.
	 * @return The response to the input request, or null if something
	 *         goes wrong
	 */
	public String getStringInput(String prompt) {
		String ret = null;
		try {
			System.out.print(prompt);
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			ret = reader.readLine();
		} catch (IOException e) {
			/* Somthing went wrong, report */
			System.out.println("Failed to read input from standard input. Reason:"
					+ e.getMessage());
		}

		return ret;
	}
}
